package org.om.action;

import org.om.dto.ModulesVo;
import org.om.excepion.BusinessException;
import org.om.model.Users;
import org.om.service.UserService;
import org.redkale.net.http.HttpRequest;
import org.redkale.net.http.HttpResponse;
import org.redkale.net.http.WebServlet;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * The type User servlet.
 *
 * @author :<a href="mailto:penggangshu@ebnew.com">舒彭钢</a>
 * @date :2016-07-01 17:11:29
 */
@WebServlet(value = {"/user/*"}, moduleid = ModulesVo.MODULE_USER)
public class UserServlet extends  BaseServlet{
    @Resource
    private UserService userService;

    @AuthIgnore
    @WebAction(url = "/user/login")
    public void login(HttpRequest req, HttpResponse resp) throws IOException {
        Users loginUser = req.getJsonParameter(Users.class, "login");
        String message="";
        try {
            boolean bool =  userService.login(loginUser);
            if(bool){
                message = "{\"success\":true, \"retcode\":1, \"message\":\"Login Success\"}";
            }
        } catch (BusinessException e) {
            message = "{\"success\":false, \"retcode\":2, \"message\":\""+e.getMessage()+"\"}";
        }
        resp.finish(message);

    }
}
